﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Factory;
using BLL;
using System.Data;

namespace MyWorkspace
{
    public partial class AuthorityList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetAuthorityList(); 
        }

        private void GetAuthorityList()
        {
            IAuthorityRepository authoritymanage = AuthorityManageFactory.InitializeAuthorityRepository();
            Reapeater1.DataSource = authoritymanage.GetAuthorityAndLevel();//指定数据源
            Reapeater1.DataBind();//绑定数据
        }

        protected void CreateButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("CreateNewAuthority.aspx");
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;//把事件传给Button
            int id = int.Parse(btn.CommandArgument);//前台界面中的commandArgument，可以获取到需要的Id
            IAuthorityRepository authorityDelete = AuthorityManageFactory.InitializeAuthorityRepository();
            authorityDelete.DeleteAuthority(id);
            Response.Write("<script language=javascript>alert('删除成功！')</script>");
            GetAuthorityList();
        }

        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;//把事件传给Button
            int id = int.Parse(btn.CommandArgument);//前台界面中的commandArgument，可以获取到需要的Id
            Response.Redirect("UpdateAuthority.aspx?id="+id);
        }
    }
}